
var check1 = '0';
var verifyCode = '';   //服务器返回的验证码
var serviceUrl = $api.getStorage('serviceUrl');

apiready = function () {
	
}

////获取验证码
function getCode(){

	var mobile=$api.val($api.byId('mobile'));
	var mobilereg=/^0?(13[0-9]|15[012356789]|18[02356789]|14[57])[0-9]{8}$/;
	
	if(!mobilereg.test(mobile)){
		toast('手机号格式错误!');
		check1="1";
		$api.attr($api.byId("mobile"),'style','border:1px solid red');
		return;
	}else{
		GetValidateCodeClick();
	}
};

//计时器
var i = 60;
var timer ;
function runTime(){
	i--;
	$api.text($api.byId('sec_reload'), ""+i);
	if( i <= 0 ){
		verifyCode = '';
		$api.addEvt($api.byId('btn_getValiData'), 'click',function(){
		 	GetValidateCodeClick()
		 });
		$api.removeAttr($api.byId('btn_getValiData'), 'disabled')
		
		
		$api.css($api.dom(".tip"),'display:none');
		i = 60;
		clearTimeout(timer);
	}
	timer = setTimeout("runTime()",1000);
}

function GetValidateCodeClick(){

    var mobile = $api.val($api.byId('mobile'));

    $api.rmEvt($api.byId('btn_getValiData'), 'click', function(){});
	$api.attr($api.byId('btn_getValiData'),'disabled',true);
	
	if(timer){clearTimeout(timer);}
	runTime();
	i = 60;
	$api.css($api.dom(".tip"),'color:red;display:block;');
	
	do_ajax('/app/sendcode2','post',{'mobile':mobile},function(resData,err){
	    api.hideProgress();
		if(resData.resultCode == '0'){
			verifyCode =  resData.code;
			toast(resData.data);
   		}else{
   			toast(resData.data);
   			
   			$api.addEvt($api.byId('btn_getValiData'), 'click', function(){
			 	GetValidateCodeClick()
			 });
   			$api.attr($api.byId('btn_getValiData'),'disabled','disabled');
   			$api.removeCls($api.byId('btn_getValiData'), 'ggl_ny_btn_disable');
			
			$api.css($api.dom(".tip"),'color:red;display:none;');
			clearTimeout(timer);	
   		}
   });

};


//提交手机号
function dosubmitPhonezh(){
   	var mobile = $api.val($api.byId('mobile'));
   	var resetpassword = $api.val($api.byId('resetpassword'));
    var updatpassword = $api.val($api.byId('updatpassword'));
    var verify = $api.val($api.byId('verify'));
    	
 	if(mobile==''){
    	 toast('请填写手机号码！');
		 return;
    }
    
    if(resetpassword==''){
    	 toast('请填写重置密码！');
		 return;
    }
    
	if(updatpassword==''){
    	 toast('请填写再次确认密码！');
		 return;
    }
    
    if(resetpassword!=updatpassword){
    	 toast('两次输入密码不一致！');
		 return;
    }
    
    if(verify==''){
    	 toast('请填写验证码!');
		 return;
    }
	  	
	if(verify!=verifyCode){
		toast('验证码错误!');
		return;
	}
	
	do_ajax('/app/member/replacepwd','post', {'account':mobile,'password':resetpassword}, function(resData,err){
	    api.hideProgress();
	    
		if(resData.resultCode == '0'){
			toast(resData.datas);
			
			api.closeWin();
   		}else{
   			toast(resData.datas);	
   		}
   });
};



